--POUR CONTROLE


define erp='erp_mli2.' ;
define outils='outils_mli2.' ;



--CREATE TABLE se_par_parite AS (SELECT * FROM &erp.par_parite WHERE 1=2);



DELETE FROM  se_par_parite ;


INSERT INTO se_par_parite
 (SELECT dat.id DEVISE_COD,
         To_Date('31/12/1967','dd/mm/yyyy')+dat.datapp PARITE_DAT,
         0 ENREG_ID,
         Nvl(pe.pariteeur,0)/10000 PARITE,
         NULL VALID_DAT
  FROM UV_MPARITES_datapp dat,uv_mparites_parite pp,uv_mparites_pariteeur pe
  WHERE dat.id=pp.id AND dat.RANGMULTI2=pp.RANGMULTI2
    AND dat.id=pe.id AND dat.RANGMULTI2=pe.RANGMULTI2
    /*AND To_Date('31/12/1967','dd/mm/yyyy')+dat.datapp <=To_Date('18/11/2013','dd/mm/yyyy')*/
  );


 UPDATE se_par_parite tf SET enreg_id = (select enreg_id FROM &erp.par_parite f WHERE f.DEVISE_COD=tf.DEVISE_COD AND f.PARITE_DAT=tf.PARITE_DAT ) ;
 UPDATE se_par_parite tf SET enreg_id=&outils.enreg_id.NEXTVAL WHERE enreg_id IS NULL OR enreg_id=0;


 CALL uvse_synchroverserp('DEVISE_COD@PARITE_DAT','PAR_PARITE','O') ;

COMMIT;

SELECT &outils.stragg(source) source,devise_cod, parite_dat, enreg_id, parite, valid_dat
FROM (
  SELECT 'uv' source ,g.* FROM se_par_parite g
  UNION ALL
  SELECT 'se' source ,g.* FROM &erp.par_parite g
  )
GROUP BY devise_cod, parite_dat, enreg_id, parite, valid_dat
HAVING Count(1)!=2
ORDER BY devise_cod,parite_dat;